package com.eascs.admin.o2o.loan.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.admin.o2o.internal.util.StatusContexts;
import com.eascs.admin.o2o.loan.dao.LoanapplyOpLogDao;
import com.eascs.admin.o2o.loan.entity.O2oLoanBkpInfo;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.common.util.StringUtil;

@Service
public class O2oLoanBkpService implements IO2oLoanGsScService<O2oLoanBkpInfo> {

	@Autowired
	LoanapplyOpLogDao dao;
	
	public int insertEntity(O2oLoanBkpInfo t) {
		return dao.insert(t);
	}

	public int updateEntity(O2oLoanBkpInfo t) {
		return dao.updateById(t);
	}

	public O2oLoanBkpInfo getEntityById(String id) {
		return dao.getById(O2oLoanBkpInfo.class, id);
	}

	public List<O2oLoanBkpInfo> queryEntitys(O2oLoanBkpInfo t) {
		return null;
	}

	public int queryEntitysSize(String loanapplyNo ) {
		String sql =  "select count(*) from o2o_loan_bkp_info where loanapply_id=? and is_delete = 'N' ";
		return dao.findInteger(sql, loanapplyNo);
	}
	
	public PageResult<Object[]> queryPage(O2oLoanBkpInfo t, int pageSize, int pageIndex) {
		SqlPageQuery<Object[]> pageQuery = new SqlPageQuery<>(Object[].class, pageSize, pageIndex);
		String querySql = "select id,product_name,brand,model,buying_price,selling_price,last_month_sales,loanapply_id from o2o_loan_bkp_info where 1=1 ";
		if(StringUtil.isNotBlank(t.getLoanapplyId())){
			querySql = querySql + " and loanapply_id=? "; 
			pageQuery.addParam(t.getLoanapplyId());
		}
		querySql = querySql + " and is_delete=? "; 
		pageQuery.addParam(StatusContexts.O2O_NO);
		pageQuery.setQuerySql(querySql);
		return dao.findDataWithPage(pageQuery);
	}

}
